/*******************************************************************************
 * Copyright (c) 2011 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package com.takaharabooks.mhp3rd;

import android.app.Activity;
import android.view.View;
import android.widget.ProgressBar;

import com.admob.android.ads.AdListener;
import com.admob.android.ads.AdView;
import jp.co.nobot.libAdMaker.libAdMaker;



class ConbinateAdView
{
	// Admaker定数===========================================================
    //private static final String TAG = "AdActivity";
    private static final String ADMAKER_URL = "http://images.ad-maker.info/apps/3odp5nekfhm5.html";
    //=======================================================================
	
	// プログレスバー
	ProgressBar m_loading;
	// AdMaker
	libAdMaker m_csAdMaker;
	// AdMob
	AdView m_csAdMob;

	// コンストラクタ
	// プログレスバーを初期化
	public ConbinateAdView(ProgressBar loading){
		m_loading = loading;
	}

    /*************************************
     * 広告初期化（AdMaker）
     **************************************/
	public void InitAdMaker(libAdMaker mv, Activity ac){
        m_csAdMaker = mv;
        m_csAdMaker.setActivity(ac);
	}
	
    /*************************************
     * 広告初期化（AdMob）
     **************************************/
    protected void InitAdMob(AdView adView)
    {
    	m_csAdMob = adView;
    	m_csAdMob.setAdListener(new AdListener() {
            @Override
			public void onReceiveRefreshedAd(AdView adView) {
            	// AdListener.onReceiveRefreshedAd called!
            }
 
            @Override
			public void onReceiveAd(AdView adView) {
            	// AdListener.onReceiveAd called!
                // 広告が表示できたのでProgressBarを消す
            	m_loading.setVisibility(View.GONE);
            }
 
            @Override
			public void onFailedToReceiveRefreshedAd(AdView adView) {
                // AdListener.onFailedToReceiveRefreshedAd called!
            }
 
            @Override
			public void onFailedToReceiveAd(AdView adView) {
                // AdListener.onFailedToReceiveAd called!
                // AdMakerの広告を表示するのでAdViewの更新を行わせない
                m_csAdMob.setRequestInterval(0);
                m_csAdMob.setVisibility(View.GONE);
                // AdMakerの広告を表示させる
                showAdMaker();                
            }
        });
    }
	
    /*************************************
     * 広告を表示させる（AdMaker）
     **************************************/   
    protected void showAdMaker()
    {
        // プログレスバーを消す
        m_loading.setVisibility(View.GONE);
        // 広告表示
        m_csAdMaker.setVisibility(View.VISIBLE);
        m_csAdMaker.siteId = "401";
        m_csAdMaker.zoneId = "1018";
        m_csAdMaker.setUrl(ADMAKER_URL);
        m_csAdMaker.start();
    }
}